package com.yjt.fresh.adpater;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yjt.fresh.R;
import com.yjt.fresh.bean.BeanCoupon;
import com.yjt.fresh.constant.MyConstants;

import java.util.List;

/**
 * 我的优惠券
 * Created by mcc on 2018/6/10.
 */

public class AdpRvAtyMyCoupon extends BaseQuickAdapter<BeanCoupon.ListBean, BaseViewHolder> {

    private int mStatus;
    private boolean mIsShowCb;
    private boolean mIsCheck;

    public AdpRvAtyMyCoupon(int layoutResId, @Nullable List<BeanCoupon.ListBean> data) {
        super(layoutResId, data);
    }

    public void setStatus(int status) {
        mStatus = status;
    }
    public void isCheck(boolean isCheck){
        mIsCheck = isCheck;
        notifyDataSetChanged();
    }


    public void isShowCb(boolean isShowCb){
        mIsShowCb = isShowCb;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, final BeanCoupon.ListBean item) {
        CheckBox cb = helper.getView(R.id.cbAppAtyMyCoupon);
        TextView tvMoney = helper.getView(R.id.tv_app_recycle_item_aty_my_coupon_money);
        TextView tvUnit = helper.getView(R.id.tv_app_recycle_item_coupon_money_unit);
        TextView tvContent = helper.getView(R.id.tvAppAtyMyCouponContent);
        TextView tvType = helper.getView(R.id.tvAppAtyMyCouponType);
        TextView tvTime = helper.getView(R.id.tvAppAtyMyCouponTime);
        TextView tvStatus = helper.getView(R.id.tvAppAtyMyCouponStatus);

        helper.addOnClickListener(R.id.tvAppAtyMyCouponStatus);
        if ("1".equals(item.getCOUPONTYPE())) {//满减
            tvUnit.setVisibility(View.VISIBLE);
            tvMoney.setText(item.getCOUPON_REDUCE_MONEY() + "");
        } else if ("2".equals(item.getCOUPONTYPE())) {//折扣
            tvUnit.setVisibility(View.GONE);
            tvMoney.setText((item.getDISCOUNT()*10) + "折");
        }

        tvContent.setText("【满" + item.getCOUPON_FULL_MONEY() + "元使用】");

        tvType.setText(item.getTITLE());
        tvTime.setText(item.getCOUPON_START_DATE() + "至" + item.getCOUPON_END_DATE());

        switch (mStatus) {
            case MyConstants.NOT_YET:
                tvStatus.setTextColor(mContext.getResources().getColor(R.color.color_43b624));
                tvStatus.setBackgroundResource(R.drawable.zz_shape_43b624_border_5);
                tvStatus.setText("立即使用");
                break;
            case MyConstants.ALREADY:
                tvStatus.setTextColor(mContext.getResources().getColor(R.color.color_333333));
                tvStatus.setBackgroundResource(R.drawable.shape_e6e6e6_5);
                tvStatus.setText("已使用");
                break;
            case MyConstants.OVERDUE:
                tvStatus.setTextColor(mContext.getResources().getColor(R.color.color_333333));
                tvStatus.setBackgroundResource(R.drawable.shape_e6e6e6_5);
                tvStatus.setText("已过期");
                break;
        }
        cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                item.setCheck(isChecked);
            }
        });
        if (mIsShowCb){
            cb.setVisibility(View.VISIBLE);
        }else {
            cb.setVisibility(View.GONE);
        }
        cb.setChecked(mIsCheck);
    }
}
